package org.example.buysystem.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.buysystem.entity.Avatar;
import org.example.buysystem.entity.Icon;
import org.example.buysystem.entity.IconCategory;
import org.example.buysystem.mapper.AvatarMapper;
import org.example.buysystem.mapper.IconCategoryMapper;
import org.example.buysystem.mapper.IconMapper;
import org.example.buysystem.utils.BaseApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class IconService extends ServiceImpl<IconMapper, Icon> {

    @Resource
    private IconMapper iconMapper;

    @Autowired
    private IconCategoryMapper iconCategoryMapper;

    public List<Icon> getIconCatehoryMapList() {
        return iconMapper.getIconCatehoryMapList();


    }

    public Map<String, Object> deleteById(Long id) {

        Long count=iconCategoryMapper.selectCount(
                new QueryWrapper<IconCategory>().eq("icon_id",id));
        if(count>0){
            return BaseApi.error("改上级分类存在下级分类，请删除所有下级分类再尝试删除");
        }
        super.removeById(id);
        return BaseApi.success();
    }
}
